home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / interupt.mac < prev    next >
Text File  |  1985-06-03  |  4KB  |  207 lines

  1. ;MACROS for items that replace BIOS calls
  2. ;
  3. ;    Prolog Segname
  4. ;        start of code should be labeled
  5. ;        ENTRY:
  6. ;
  7. ;    Epilog    IntNo,Pointr,SegName
  8. ;        IntNo is interrupt number
  9. ;        Pointr is name of data area DD
  10. ;
  11. ;    Finish    SegName,StackSize
  12. ;  the variable  zzarg gets set to the first word (two chars) entered
  13. ;    on the command line
  14. ;
  15. ;    Finish has first label of CONFIG:
  16. ;    if HIMSG exists it is printed (put after Epilog)
  17. ;    eg    jmp CONFIG
  18. ;       HIMSG db 'hello$'
  19.  
  20.  
  21. ; Prolog SegName
  22. ;    This pushes a bit and then runs to the rest
  23. ;    name the segment here
  24.  
  25. Prolog    MACRO    SegName
  26. pBase    equ    00h    ;pBase of memory (seg)
  27. zbufr    equ    5Dh
  28.  
  29.  
  30.  
  31. DGROUP    GROUP    SegName,ZzUseStk
  32.  
  33. SegName    Segment    para
  34.  
  35. Moveit    PROC    FAR
  36.    ASSUME    CS:SegName
  37.  
  38. ;Set up the stack so a RET instruction
  39. ;    will jump to the
  40. ;    beginning of program segment
  41.     push    ds    ;Prog segment
  42.     xor    ax,ax
  43.     push    ax    ;Offset
  44.  
  45.     jmp    DoTheRest
  46.  
  47.     db    '1982 MSZachmann'
  48. MoveIt    endp
  49.     ENDM
  50. ;    Epliog    IntNo,Pointr
  51. ;
  52. ;  This does the work of checking 
  53. ; that no other one has been loaded.
  54. ; Just exits if other loaded. IntNo
  55. ; is the interrupt number
  56. ; Pointer is a pointer to where the 
  57. ; old address should be stored.
  58.  
  59.  
  60. Epilog    MACRO    IntNo,Pointr,SegName
  61. EndEntry label    near
  62.  
  63. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  64. ;
  65. ;    Temporary stuff
  66. ;
  67. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  68.  
  69.  
  70. Initial    proc    near
  71. DoTheRest    LABEL    NEAR
  72.  
  73. ;Check to see if already loaded.
  74. ; if so, exit
  75. ;
  76.     mov    BX,zbufr
  77.     mov    AX,[BX]
  78.     mov    CS:zzarg,AX
  79.     push    DS
  80.     mov    AX,pBase
  81.     mov    DS,AX
  82.     mov    BX,4*IntNo
  83.     LES    SI,dword ptr [BX]
  84. ;now have start address of code
  85.     mov    SI,offset ENTRY    ;start here
  86.     mov    DI,SI
  87.     mov    AX,CS
  88.     mov    DS,AX    ; all set for compare
  89.     CLD    ;forward
  90.     mov    CX,010    ;should suffice
  91.     REPE    CMPSW
  92.     pop    DS
  93. ; now set status byte to 0FFFh
  94.     mov    AX,0FFFFh
  95.     push    AX
  96.     jne    short    Nxt1
  97.     jmp    Config
  98.  
  99.  
  100. ;Modify the INT 20H instruction at DS:1
  101. ;    Make it an INT 27h
  102. Nxt1:    mov    BX,1
  103.     mov    BYTE PTR [BX],27h
  104.  
  105. ;relocate down a page using CS:->DS:
  106. ;
  107.     mov    AX,DS
  108.     mov    ES,AX    ;set ES to page lower
  109.     mov    AX,CS
  110.     mov    DS,AX    ;set DS to here
  111.     mov    SI,offset ENTRY
  112.     mov    DI,SI    ;both same
  113.     mov    CX,offset EndEntry-offset ENTRY
  114.     shr    CX,1    ;div by 2 for wds
  115.     inc    CX    ;for luck
  116. lz1:    rep movsw
  117.     and    CX,CX
  118.     jnz    lz1
  119.  
  120. ;Set DS:BX to point to int vector IntNo
  121. ;        (Pointr i/o )
  122.     MOV    AX,pBase
  123.     MOV    DS,AX
  124.     MOV    BX,4*IntNo
  125.  
  126.  
  127.     push    ES    ;save new page
  128.  
  129. ;Set ES:DI to old vector 10h
  130.     LES    DI,DWORD PTR [BX]
  131.  
  132. ;Reset the vector to Entry point
  133.     MOV    WORD PTR [BX],offset ENTRY
  134.     pop    CX    ;new page number
  135.     MOV    WORD PTR [BX+2],CX
  136.  
  137. ;Now put the old vector address
  138. ;    into the call pointer at
  139. ;    DS:Pointr
  140.    ASSUME   DS:&SegName
  141. ;actually DS is SegName-100h
  142.     MOV    DS,CX
  143.     MOV    Pointr,DI
  144.     MOV    Pointr+2,ES
  145. ;set status to NEW 
  146.     pop    AX    ;get status back
  147.     xor    AX,AX
  148.     push    AX    ;for later
  149. Initial    endp
  150.  
  151.     ENDM
  152.  
  153. ;    Finish
  154. ; exits
  155. ;    takes segment name and stack size
  156.  
  157. Finish    MACRO    SegName,SSizez
  158.  
  159.  
  160. ;Set up DX to the program size, note
  161. ;    that CS is 100h larger than
  162. ;    program prefix segment
  163. ; ! This is the lazy way, and
  164. ;    assumes PC-DOS stays consistent.
  165.  
  166. Nconfig    proc    far
  167. CONFIG    label    near
  168.     mov    AX,CS
  169.     mov    DS,AX    ;for print screen
  170.     IFDEF    HIMSG
  171.     mov    AH,9    ;print string
  172.     mov    DX,offset CLearstr
  173.     int    21h    ;DOS
  174.     mov    DX,offset HIMSG
  175.     int    21h
  176.     ENDIF
  177.  
  178.     pop    AX    ;get status
  179.     and    AX,AX    ;if zero then new
  180.     jz    CONF3
  181.     mov    DX,offset AlThere
  182.     mov    AH,9
  183.     int    21h    ;print
  184. CONF3:    MOV    DX,offset endENTRY
  185.     RET    ;Exit from the system
  186.         ;By doing an INT 27h
  187. ALThere    db    '*** This program was already loaded. ***',13,10,'$'
  188. zzarg    dw    ?    ;will contain first word at 80h
  189. Clearstr db    13
  190.     db    27 dup(10)
  191.     db    '$'
  192. Nconfig    endp
  193.  
  194.  
  195.  
  196. SegName    ends
  197.  
  198. ; ensure that stack gets loaded highest in memory
  199. ; by naming it large (ZZ...)
  200.  
  201. ZzUSERST    segment    STACK
  202.     dw    SSizez dup (?)
  203. ZzUSERST    ENDS
  204.  
  205.  
  206.     ENDM
  207.